#redirect -file -tee ./log/std_filler.log {source ./scripts/std_filler.tcl}
################################
# setup and proc
# ##############################
source -e -v user_scripts/global_setup.tcl
source -e -v user_scripts/block_setup.tcl
source -e -v user_scripts/loadInnovus.tcl

set current_step "std_filler"
set previous_step "route_opt"

set report_dir "reports/${current_step}"
if {![file exist $report_dir]} {file mkdir $report_dir}

#####################################
# open design
# ##################################
restoreDesign ${DESIGN_LIBRARY}/${DESIGN_NAME}.${previous_step}.dat $DESIGN_NAME

# common setting
source -e -v user_scripts/common_setting.tcl




############################################
#Pre-place customizations
############################################
if {[file exists $PRE_SCRIPT($current_step)]} {
		puts "INFO: Sourcing $PRE_SCRIPT($current_step)"
		source $PRE_SCRIPT($current_step)
} else {
		puts "WARN: $PRE_SCRIPT($current_step) not exist. Skip to source it."
}


############################################
# Core command
############################################
############################################
# Filler cell insertion
############################################
deleteAllCellPad

set DCAP_CELLS "FILE128HM FILE64HM FILE32HM FILE16HM FILE8HM FILE4HM FILE3HM"
set FILLER_CELLS "FIL64HM FIL32HM FIL16HM FIL8HM FIL4HM FIL2HM FIL1HM"

#filler with metal
setFillerMode -corePrefix DCAP
setFillerMode -core $DCAP_CELLS
setFillerMode -add_fillers_with_drc false
addFiller -doDRC true

## filler without metal
setFillerMode -corePrefix NORMAL_FILLER
setFillerMode -core $FILLER_CELLS
addFiller -doDRC false

# calculate ratio
set total_cell [llength [dbGet top.insts.name]]
set decap_cell [llength [dbGet top.insts.name *DCAP*]]
set filler_cell [llength [dbGet top.insts.name *NORMAL_FILLER*]]

set decap_ratio [expr double($decap_cell)/$total_cell*100]
set filler_ratio [expr double($filler_cell)/$total_cell*100]

Puts "INFO: filler cell ratio ..."
Puts [format "DCAP %.2f%%, NORMAL FILLER %.2f%%" $decap_ratio $filler_ratio]

# ecoRoute
if {$STD_FILLER_DO_DRC_FIX} {
		setNanoRouteMode -routeWithEco true
		ecoRoute
}



#####################################
# Post-route customizations
# ##################################
if {[file exists $POST_SCRIPT($current_step)]}  {
		puts "INFO: Sourcing $POST_SCRIPT($current_step)"
		source $POST_SCRIPT($current_step)
} else {
		puts "WARN: $POST_SCRIPT($current_step) not exist. Skip to source it."
}


############################
# PG connection
# ##########################
source -e -v user_scripts/pg_connection.tcl


# change names
if {$CHANGE_NAME} {
		source -e -v user_scripts/change_name.tcl
}

# pinShape
source -e -v user_scripts/createPinShape.tcl

# text
source -e -v user_scripts/create_text.tcl


saveDesign ${DESIGN_LIBRARY}/${DESIGN_NAME}.${current_step}


###################################################
# Report
# ##############################################
if {$REPORT_QOR($current_step)} {
		source -e ./user_scripts/report_qor.tcl
} else {
		puts "INFO: Skip report for step: $current_step"
}

date > ${current_step}

exit






